package com.xiaoyushu.xiaoyushu.auth.rpc;


import com.xiaoyushu.framework.common.response.Response;
import com.xiaoyushu.user.api.UserFeignApi;
import com.xiaoyushu.user.dto.req.FindUserByPhoneReqDTO;
import com.xiaoyushu.user.dto.req.RegisterUserReqDTO;
import com.xiaoyushu.user.dto.req.UpdateUserPasswordReqDTO;
import com.xiaoyushu.user.dto.resp.FindUserByPhoneRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class UserRpcService {
    @Resource
    private UserFeignApi userFeignApi;

    public void updatePassword(String encodePassword){
        UpdateUserPasswordReqDTO updateUserPasswordReqDTO =new UpdateUserPasswordReqDTO();
        updateUserPasswordReqDTO.setEncodePassword(encodePassword);
        userFeignApi.updatePassword(updateUserPasswordReqDTO);
    }
    /**
     * 用户注册
     */
    public Long register(String phone) {
        RegisterUserReqDTO registerUserReqDTO = new RegisterUserReqDTO();
        registerUserReqDTO.setPhone( phone);
        Response<Long> longResponse = userFeignApi.registerUser(registerUserReqDTO);

        if (!longResponse.isSuccess()){
            return null;
        }
        return longResponse.getData();
    }
    public FindUserByPhoneRspDTO findUserByPhoneRspDTO(String phone){
        FindUserByPhoneReqDTO findUserByPhoneReqDTO = new FindUserByPhoneReqDTO(phone);
        findUserByPhoneReqDTO.setPhone(phone);
        Response<FindUserByPhoneRspDTO> findUserByPhoneRspDTOResponse = userFeignApi.findUserByPhone(findUserByPhoneReqDTO);
        if (!findUserByPhoneRspDTOResponse.isSuccess()){
            return null;
        }
        return findUserByPhoneRspDTOResponse.getData();
    }


}
